﻿//设计模式 - 备忘录模式
//目的：保存历史记录，随时恢复
var history = new History();
var user = new User { Name = "第一次记录" };
history.Add(user.Save());

user.Name = "修改了值";
history.Add(user.Save());

user.Name = "第三次修改";
history.Add(user.Save());

Console.WriteLine("获取第二次修改：{0}", history.Get(1).User.Name);
Console.WriteLine("获取第一次修改：{0}", history.Get(0).User.Name);




Console.ReadKey();

class User
{
    public string Name { get; set; }

    public Momento Save() => new(new() { Name = Name });

    public User Restor(Momento momento) => momento.User;
}

class Momento
{
    public Momento(User user)
    {
        User = user;
    }

    public User User { get; }
}

class History
{
    List<Momento> Momentos { get; set; } = new();

    public void Add(Momento momento) => Momentos.Add(momento);
    public Momento Get(int version) => Momentos[version];
}